package book;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.*;

public class Login {    //登录界面
    JFrame f1;
    JPanel p1;
    JButton b1,b3;
    JLabel l1, l2;
    JTextField t1;
    JPasswordField s1;

    public Login() {
        f1 = new JFrame("登陆");
        p1 = new JPanel();
        b1 = new JButton("注册");
        l1 = new JLabel("学号：");
        t1 = new JTextField(18);
        l2 = new JLabel("密码：");
        s1 = new JPasswordField(18);
        b3 = new JButton("登陆");

        p1.setLayout(null);
        l1.setBounds(100, 120, 40, 30);
        t1.setBounds(140, 120, 200, 30);
        l2.setBounds(100, 165, 40, 30);
        s1.setBounds(140, 165, 200, 30);
        b1.setBounds(250, 220, 70, 30);
        b3.setBounds(140, 220, 70, 30);

        f1.add(p1);
        p1.add(l1);
        p1.add(t1);
        p1.add(l2);
        p1.add(s1);
        p1.add(b3);
        p1.add(b1);

        f1.setVisible(true);
        f1.setBounds(600, 250, 500, 500);

        //登录按钮监听器
        b3.addActionListener(new ActionListener() {
            Boolean flag;
            @Override
            public void actionPerformed(ActionEvent e) {
                String  id= t1.getText();
                String password = new String(s1.getPassword());
                flag = text.search(id,password);
                if( flag) {
                    f1.dispose();
                }

            }
        });

        //注册按钮监听器
        b1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new Registration();
                f1.dispose();
            }
        });

        f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

}